package com.yibai.web.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yibai.web.app.entity.ArticleImg;
import com.yibai.web.app.mapper.ArticleImgMapper;
import com.yibai.web.app.service.ArticleImgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-04-19
 */
@Service
public class ArticleImgServiceImpl extends ServiceImpl<ArticleImgMapper, ArticleImg> implements ArticleImgService {

    @Override
    public void insertImages(Integer id,String imgs) {
        String imgList[] = imgs.split(",");
        ArticleImg articleImg = null;
        if(imgList.length>1){
            for(int i =0;i<imgList.length;i++){
                articleImg = new ArticleImg();
                articleImg.setArticleId(id);
                articleImg.setImageUrl(imgList[i]);
                baseMapper.insert(articleImg);
            }
        }
    }

    @Override
    public List<ArticleImg> getImgs(Integer id) {
        QueryWrapper<ArticleImg> wrapper = new QueryWrapper<>();
        wrapper.eq("article_id",id);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public void deleteImgs(Integer id) {
        QueryWrapper<ArticleImg> wrapper = new QueryWrapper<>();
        wrapper.eq("article_id",id);
        baseMapper.delete(wrapper);
    }
}
